﻿using Aspose.Words;
using Aspose.Words.Saving;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;

namespace ConsoleApp3
{
    class Program
    {
        [Obsolete]
        static void Main(string[] args)
        {

            var word = @"C:\Users\wex\Desktop\添加主要领导流程-2020-4-7.docx";
            var wordout = @"C:\Users\wex\Desktop\test\";
            var outPath = @"C:\Users\wex\Desktop\real\test.tif";


            var pdf = @"C:\Users\wex\Desktop\调度切换上屏-发布步骤.pdf";





            //WordMain(word, wordout, outPath);



        }

        [Obsolete]
        private static void WordMain(string word, string wordout, string outPath)
        {
            Word2Tifs(word, wordout);

            if (!Directory.Exists(wordout))
            {
                Directory.CreateDirectory(wordout);
            }
            var list = Directory.GetFiles(wordout);

            SplicingImg(outPath, list);

            Directory.Delete(wordout, true);
        }

        [Obsolete]
        static void Word2Tifs(string docFullPath, string dirFullPath)
        {
            Document doc = new Document(docFullPath);
            ImageSaveOptions iso = new ImageSaveOptions(SaveFormat.Tiff);
            iso.Resolution = 128;
            iso.PrettyFormat = true;
            for (int i = 0; i < doc.PageCount; i++)
            {
                iso.PageIndex = i;
                doc.Save($@"{dirFullPath}\" + i + ".tif", iso);
            }
        }

        static void SplicingImg(string outPath, IList<string> imgPaths)
        {
            var maps = new List<Bitmap>();
            foreach (var item in imgPaths)
            {
                maps.Add(new Bitmap(item));
            }
            var width = maps.Max(a => a.Width);
            var height = maps.Sum(a => a.Height);
            Bitmap bitMap = new Bitmap(width, height);
            Graphics g = Graphics.FromImage(bitMap);
            g.FillRectangle(Brushes.White, new Rectangle(0, 0, width, height));

            var tempHeight = 0;
            foreach (var item in maps)
            {
                g.DrawImage(item, 0, tempHeight, item.Width, item.Height);
                tempHeight += item.Height;
                item.Dispose();
            }
            Image img = bitMap;
            img.Save(outPath);
            img.Dispose();
        }
    }
}